package com.thuanpq.activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.PreferenceActivity;
import com.thuanpq.R;
import com.thuanpq.global.GlobalCons;

public class PrefActivity extends PreferenceActivity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		addPreferencesFromResource(R.xml.pref);

		getPreferenceManager().setSharedPreferencesName(
				GlobalCons.SHARED_PREF_NAME);
	}

	@Override
	protected void onStart() {
		super.onStart();

		getPrefs();
	}

	private void getPrefs() {
		// we need to show the user's existing prefs, this isn't done
		// automatically by the activity
		SharedPreferences myprefs = getSharedPreferences(
				GlobalCons.SHARED_PREF_NAME, 0);

		((CheckBoxPreference) findPreference(GlobalCons.SHARED_PREF_REJECT_CALL))
				.setChecked(myprefs.getBoolean(
						GlobalCons.SHARED_PREF_REJECT_CALL, false));
		((CheckBoxPreference) findPreference(GlobalCons.SHARED_PREF_ANSWER_CALL))
				.setChecked(myprefs.getBoolean(
						GlobalCons.SHARED_PREF_ANSWER_CALL, false));
		((EditTextPreference) findPreference(GlobalCons.SHARED_PREF_ANSWER_PERIOD))
				.setText(myprefs.getString(
						GlobalCons.SHARED_PREF_ANSWER_PERIOD, "0"));
	}
}